#include <iostream>
#include <cstring>
using namespace std;
int T;
const int N = 2e5 + 10;

int a[N];

int main()
{
	cin >> T;
	while(T--)
	{
//		memset(a, 0, sizeof a);
//		int maxa = 0;
		int cnt = 0;
		int n; cin >> n;
		bool flag = false;
		for(int i = 1; i <= n; i++) 
		{
			int x; cin >> x;
			if(x == 0) cnt++;
			if(x >= 2) flag = true;
		}
		if(cnt <= (n +1)/ 2) cout << 0 << endl;
		else if(flag || cnt == n) cout << 1 << endl;
		else cout << 2 << endl;

//		cout << i << endl;
	}
	return 0;
}
